UAS DATABASE
df <- data.frame(
geo = c("IDN", "USA", "FRA", "CHN", "BRA"),
Negara = c("Indonesia", "Amerika Serikat", "Perancis", "China", "Brazil"),
Benua = c("Asia", "Amerika", "Eropa", "Asia", "Amerika Selatan"),
Tahun = c(2020, 2020, 2020, 2020, 2020),
Angka_Harapan_Hidup = c(71.5, 78.8, 82.5, 76.3, 74.0),
Pendapatan_per_kapita = c(4000, 65000, 45000, 10000, 9500),
Populasi = c(273000000, 331000000, 67000000, 1400000000, 212000000),
Jumlah_anak = c(2.3, 1.8, 1.9, 1.6, 2.2)
)library(ggplot2)
histogram_plot <- ggplot(df, aes(x = Angka_Harapan_Hidup)) +
geom_histogram(binwidth = 2, fill = "skyblue", color = "black") +
ggtitle("Distribusi Angka Harapan Hidup") +
xlab("Angka Harapan Hidup") +
ylab("Frekuensi")
print(histogram_plot)bar_chart <- ggplot(df, aes(x = Negara, y = Pendapatan_per_kapita, fill = Benua)) +
geom_bar(stat = "identity") +
ggtitle("Pendapatan per Kapita per Negara") +
xlab("Negara") +
ylab("Pendapatan per Kapita")
print(bar_chart)##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
scatter_3d <- df %>%
plot_ly(
x = ~Pendapatan_per_kapita,
y = ~Angka_Harapan_Hidup,
z = ~Populasi,
type = "scatter3d",
mode = "markers",
marker = list(size = 5, color = ~Jumlah_anak, colorscale = "Viridis")
) %>%
layout(title = "3D Scatter Plot: Pendapatan, Harapan Hidup, dan Populasi")
scatter_3dinteractive_plot <- ggplot(df, aes(x = Pendapatan_per_kapita, y = Angka_Harapan_Hidup, text = paste("Negara:", Negara))) +
geom_point(aes(color = Benua, size = Populasi)) +
ggtitle("Grafik Interaktif: Pendapatan per Kapita vs Angka Harapan Hidup")
ggplotly(interactive_plot)R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents (A. T. de Carvalho, Lechevallier, and Melo 2012). For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
Including Plots
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.
Referensi
A. T. de Carvalho, Francisco de, Yves Lechevallier, and Filipe M. de
Melo. 2012. “Partitioning Hard Clustering Algorithms Based on
Multiple Dissimilarity Matrices.” Pattern Recognition 45
(1): 447–64. https://doi.org/10.1016/j.patcog.2011.05.016.